<template>
  <div class="bg-content content">
    <ul class="list">
      <li
        v-for="(item, index) in list"
        :key="index"
        @click="goDetail(item.hospitalId)"
      >
        <div class="hos-flex">
          <div class="left">
            <div class="img" v-if="item.image">
              <img :src="item.image" alt="" />
            </div>
            <div class="img" v-else>
              <img src="../../../../assets/img/main/hos.png" alt="" />
            </div>
            <div class="text">
              <h4>{{ item.hospitalName }}</h4>
              <p>{{ item.hospitalLevel }}</p>
              <p>{{ item.address }}</p>
            </div>
          </div>
          <div class="right">
            <div class="title">医院</div>
          </div>
        </div>
      </li>
    </ul>
  </div>
</template>
<script>
import { getYuanQuOrDeptApi } from "@/service/api.js";
import Vue from "vue";
import { Cell } from "vant";
Vue.use(Cell);
export default {
  name: "index",
  data() {
    return {
      list: [],
      apptoken: "",
      hospitalId: "",
      type: ""
    };
  },
  created() {
    // 拿取apptoken
    localStorage.getItem("apptoken"),
      (this.apptoken = JSON.parse(localStorage.getItem("apptoken"))),
      console.log(this.apptoken);
    localStorage.setItem("apptoken1", this.apptoken);
    this.getBHospital(); //获取分院
  },
  methods: {
    goDetail(id) {
      this.hospitalId = id;
      let hosid = JSON.stringify(this.hospitalId);
      localStorage.setItem("hosid", hosid);
      this.$router.push({
        name: "select-department",
        query: {
          type: this.type
        }
      });
      console.log(id);
    },
    // 获取分院
    getBHospital() {
      getYuanQuOrDeptApi({
        apptoken: this.apptoken
      }).then(res => {
        console.log(res);
        console.log(res.data.type);
        this.type = res.data.type;
        if (res.code == 4000) {
          //获取成功
          if (res.data.type == 1) {
            this.list = res.data.list;
            console.log(this.list);
          } else if (res.data.type == 2) {
            // this.$router.push({
            //   name: "select-department",
            //   query: {
            //     id: this.hospitalId,
            //     type: this.type,
            //   },
            // });
          }
          console.log("list", this.list);
        } else if (res.code == 4001) {
          //获取失败
        }
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.bg-content {
  background: #f6f6f6;
  padding-top: 0.2rem;
}
.list {
  background: #ffffff;
  padding: 0 0.1rem;
  li {
    // height: 80px;
    border-bottom: 0.01rem solid #f1f1f1;
  }
}
.hos-flex {
  // height: 80px;
  padding: 0.1rem 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .left {
    display: flex;
    align-items: center;
    h4 {
      font-size: 0.4rem;
      font-family: Source Han Sans CN;
      font-weight: 400;
      color: #333333;
    }
    p {
      font-size: 0.3rem;
      font-family: Source Han Sans CN;
      font-weight: 400;
      color: #999999;
    }
    .text {
      width: 78%;
      p {
        margin: 0.05rem 0;
      }
    }
  }
  .right {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    height: 2rem;
    .title {
      width: 1rem;
      height: 0.5rem;
      background: #07c6b4;
      border-radius: 0.1rem;
      font-size: 0.2rem;
      line-height: 0.5rem;
      font-family: Source Han Sans CN;
      font-weight: 400;
      color: #ffffff;
      text-align: center;
    }
    p {
      font-size: 0.2rem;
      font-family: Source Han Sans CN;
      font-weight: 400;
      color: #999999;
    }
  }
  .img {
    width: 1.4rem;
    height: 1.4rem;
    border-radius: 0.1rem;

    margin-right: 0.2rem;
    img {
      border-radius: 0.2rem;
      width: 1.4rem;
      height: 1.4rem;
    }
  }
}
</style>
